package com.vgemv.jsutilitysdkdemo.module.share;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.RecyclerView;

import com.vgemv.jsutilitysdk.Display.JsActivityContentDisplayManager.JsActivityContentDisplayManager;
import com.vgemv.jsutilitysdk.Display.JsActivityContentDisplayManager.JsDisplayStyle;
import com.vgemv.jsutilitysdk.Menu.JsMenuFragment.JsMenuFragment.JsMenuFragment;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemStyleDefault;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemView.JsMenuItemView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVm;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVmDefault;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewAdapter;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewBasicCallback;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuViewVm;
import com.vgemv.jsutilitysdk.Reminder.JsReminderManager;
import com.vgemv.jsutilitysdk.file.JsFileManager;
import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.log.JsLogManager;
import com.vgemv.jsutilitysdk.share.JsShareManager;
import com.vgemv.jsutilitysdkdemo.module.Application.AppApplication;

import java.io.File;
import java.util.ArrayList;

public class ShareActivity extends Activity {


    public Handler mHandler = new Handler(Looper.getMainLooper());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);



        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setId(View.generateViewId());
        setContentView(linearLayout);


        JsMenuFragment menuFragment = new JsMenuFragment();
        menuFragment.moveToParentView(this,linearLayout);

        final int itemSize = JsGeometryManager.pixelFromDp(80);

        menuFragment.mBasicCallback = new JsMenuViewBasicCallback() {
            @Override
            public JsMenuViewAdapter jsMenuViewSetAdapter(JsMenuView menuView) {
                return null;
            }

            @Override
            public void jsMenuItemViewWillDisplay(RecyclerView.ViewHolder viewHolder, int position) {

            }

            @Override
            public Rect jsMenuViewSetItemOffset(JsMenuView view, int index) {
                int spanCount = view.mMenuViewVm.mi_spanCount;
                int hPadding = (JsGeometryManager.getScreenSizeInPixel().getWidth() - spanCount * itemSize)/(spanCount + 2);
                int vPadding = JsGeometryManager.pixelFromDp(20);

                Rect rect = new Rect();
                if(index == 0) {
                    rect.top = vPadding;
                    rect.left = hPadding;
                    rect.right = hPadding;
                    rect.bottom = vPadding;
                }
                else if(index == view.vms().size() - 1) {
                    rect.top = vPadding;
                    rect.left = hPadding;
                    rect.right = hPadding;
                    rect.bottom = vPadding;
                }
                else {
                    rect.top = vPadding;
                    rect.left = hPadding;
                    rect.right = hPadding;
                    rect.bottom = vPadding;
                }
                return rect;

            }

            @Override
            public JsMenuViewVm jsMenuViewSetVm(JsMenuView f) {
                JsMenuViewVm vm = new JsMenuViewVm();
                vm.mi_spanCount = 4;
                return vm;
            }

            @Override
            public JsMenuItemView jsMenuViewCreateItemView(JsMenuView f, Context context) {
                return null;
            }

            @Override
            public void jsMenuViewAfterCreateView(JsMenuView fragment) {

            }

            @Override
            public ArrayList<JsMenuItemVm> jsMenuViewSetDatasource() {
                ArrayList<JsMenuItemVm> models = new ArrayList<JsMenuItemVm>();

                JsMenuItemStyleDefault style = new JsMenuItemStyleDefault();
                style.mI_backgroundColor = Color.BLACK;
                style.mI_titleTextColor = Color.WHITE;
                style.mi_height = itemSize;
                style.mi_width = itemSize;

                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(0,"SystemShare","xxx",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(1,"x","xxx",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(2,"xxx","xxx",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(3,"xxx","xxx",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(4,"xxx","xxx",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(5,"xxx","xxx",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(6,"xxx","zzzz",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(7,"xxx","bbb",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                {
                    JsMenuItemVmDefault vm =  new JsMenuItemVmDefault(8,"bbb","zzz",itemSize,itemSize);
                    vm.setStyle(style);
                    models.add(vm);
                }
                return models;
            }

            @Override
            public void jsMenuViewClickItem(JsMenuView fragmentAlpha, int i, JsMenuItemVm model) {
                switch (i) {
                    case 0:{
                        JsLogManager.logc_d("ReminderActivity/jsMenuViewClickItem","%s","Display reminder");

                        String filePath = JsFileManager.sharedInstance().appFileDir()+"/test.txt";
                        File file = new File(filePath);
                        try {
                            if(!file.exists()) {
                                file.createNewFile();
                            }
                            JsFileManager.appendContent(file,"1111");
                        }
                        catch (Exception e) {
                            e.printStackTrace();
                        }
                        JsShareManager.shareFileViaSystem(ShareActivity.this,file);
                        break;
                    }
                    case 1:{
                        //break.
                        JsActivityContentDisplayManager.sharedInstance().undisplayLoadingReminder(ShareActivity.this);
                        break;
                    }
                    case 2: {
                        //Info
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is info", ShareActivity.this, JsReminderManager.JsMessageReminderType.Info);
                       break;
                    }
                    case 3: {
                        //warn
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is warn", ShareActivity.this, JsReminderManager.JsMessageReminderType.Warn);
                        break;
                    }
                    case 4: {
                        //error
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is error", ShareActivity.this, JsReminderManager.JsMessageReminderType.Error);
                        break;
                    }
                    case 5 : {
                        //success
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is success", ShareActivity.this, JsReminderManager.JsMessageReminderType.Success);
                        break;
                    }
                    case 6: {
                        //ForceDisunplay
                        JsActivityContentDisplayManager.sharedInstance().undisplayLoadingReminderForce(ShareActivity.this);
                        break;
                    }
                    case 7: {
                        //ForceDisunplay
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("This is a long long long long long long long long long long long long long long  success message", ShareActivity.this);
                        break;
                    }
                    case 8: {
                        //ForceDisunplay
                        JsActivityContentDisplayManager.sharedInstance().displayMessage("Hello", ShareActivity.this);
                        break;
                    }
                    default:{
                        break;
                    }
                }
            }
        };
    }
}